package main

import "sort"

func toKey(str string) string {
	bs := []byte(str)
	sort.Slice(bs, func(i, j int) bool {
		return bs[i] < bs[j]
	})
	return string(bs)
}

func groupAnagrams(strs []string) [][]string {
	m := make(map[string][]string)
	for _, str := range strs {
		key := toKey(str)
		m[key] = append(m[key], str)
	}
	result := make([][]string, 0, len(m))
	for _, arr := range m {
		result = append(result, arr)
	}
	return result
}

func main() {

}
